package com.elh.aop.factory;


import cn.hutool.core.util.ClassUtil;
import com.elh.aop.aspect.Aspect;
import com.elh.aop.interceptor.JdkInterceptor;

import java.lang.reflect.Proxy;

/**
 * @author liulei
 **/
public class JdkProxyFactory extends AbstractProxyFactory{

    @Override
    public <T> T createProxyBean(T target, Class<? extends Aspect> clazz) throws Exception {
        Aspect aspect = clazz.newInstance();
        JdkInterceptor jdkInterceptor = new JdkInterceptor(target,aspect);
        return (T)Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),jdkInterceptor);
    }
}
